@extends('Backstage.Layouts.layout')

@section('content')
    <div class="site-text site-block">
        <form class="layui-form layui-form-pane" action="">
            <input id="admin_user_id" name="id" type="hidden" value="{{$data->admin_user_id}}">
            {{csrf_field()}}
            <div class="layui-form-item">
                <label class="layui-form-label">账号</label>
                <div class="layui-input-block">
                    <input value="{{$data->admin_user_account}}"  type="text" name="param[admin_user_account]" lay-verify="required" lay-vertype="tips"  autocomplete="off" placeholder="请输入" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">账号密码</label>
                <div class="layui-input-block">
                    <input value=""  type="password" name="param[admin_user_password]"     autocomplete="off" placeholder="请输入" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">(留空则不修改)</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">真实姓名</label>
                <div class="layui-input-block">
                    <input value="{{$data->admin_user_name}}"  type="text" name="param[admin_user_name]" lay-verify="required" lay-vertype="tips"  autocomplete="off" placeholder="请输入" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">手机</label>
                <div class="layui-input-block">
                    <input value="{{$data->admin_user_phone}}"  type="text" name="param[admin_user_phone]" lay-verify="phone" lay-vertype="tips"  autocomplete="off" placeholder="请输入" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">邮箱</label>
                <div class="layui-input-block">
                    <input value="{{$data->admin_user_mail}}"  type="text" name="param[admin_user_mail]" lay-verify="email" lay-vertype="tips"  autocomplete="off" placeholder="请输入" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">角色</label>
                <div class="layui-input-block">
                    <select name="param[admin_role_id]" lay-verify="required" lay-vertype="tips" >
                        @foreach($roleData as $key=>$val)
                            <option @if(isset($data->access->admin_role_id) && $data->access->admin_role_id == $key) selected="" @endif value="{{$key}}">{{$val}}</option>
                        @endforeach
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <select name="param[admin_user_status]" lay-verify="required" lay-vertype="tips" >
                        @foreach(\App\Http\Models\Backstage\AdminUser::getStatusName('status','arr') as $key=>$val)
                            <option @if($data->admin_user_status == $key) selected="" @endif value="{{$key}}">{{$val}}</option>
                        @endforeach
                    </select>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea name="param[admin_user_remark]"  placeholder="请输入内容" class="layui-textarea">{{$data->admin_user_remark}}</textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">头像</label>
                <div class="layui-input-inline">
                    <input id="admin_user_headimg" value="{{$data->admin_user_headimg}}" type="text" name="param[admin_user_headimg]"  lay-vertype="tips"  autocomplete="off" placeholder="请输入头像网址" class="layui-input">
                </div>
                <div class="layui-input-inline">
                    <button type="button" class="layui-btn" id="upload-img">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>
                </div>
                <div class="layui-input-inline">
                    <img style="width: 80px;height: 80px" id="headimg" src="{{$data->admin_user_headimg}}">
                </div>

            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="form">立即提交</button>
                </div>
            </div>
        </form>
    </div>

@stop

@section('script')

    <script>
        layui.use(['upload','form'], function(){

            var upload = layui.upload;
            //执行实例
            var uploadInst = upload.render({
                elem: '#upload-img' //绑定元素
                ,url: '{{URL::route('admin_upload_img')}}' //上传接口
                ,data:{_token:'{{csrf_token()}}'}
                ,done: function(res){
                    //上传完毕回调
                    $('#admin_user_headimg').val(res.data.src);
                    $('#headimg').attr('src',res.data.src);
                    layer.msg('上传成功');
                }
                ,error: function(){
                    //请求异常回调
                    layer.msg('上传失败');
                }
            });

            var form = layui.form;
            //监听提交
            form.on('submit(form)', function(data){

                var $this = $(data.elem);
                $this.attr('disabled', 'disabled');
                layer.msg('数据请求中···', {
                    icon: 16
                    ,shade: 0.01
                },0);
                $.ajax({
                    url: '{{URL::route('admin_user_save')}}',
                    data: data.field,
                    type: 'post',
                    cache: false,
                    dataType: 'json',
                    success: function (data) {
                        layer.closeAll();
                        if (data['status'] == 1) {

                            layer.msg(data['msg'], { icon: 1});
                            location.replace('{{URL::route('admin_user_index')}}');

                        } else {
                            layer.msg(data['msg'], { icon: 2});
                            $this.attr("disabled",false);
                        }

                    },
                    error: function () {
                        layer.closeAll();
                        layer.msg('请求发生错误');
                        $this.attr("disabled",false);
                    }
                });

                return false;

            });
        });



    </script>
@stop

